<?php

class Timer
{
	public $name;
	public $start;
	public $stop;
	public $format;
 
	const FORMAT_S = 0;
	const FORMAT_MS = 1;
 
	function __construct($name = "Timer", $autostart = false, $format = self::FORMAT_S)
	{
		$this->name = $name;
		$this->format = $format;
		if ($autostart) $this->start();
	}
 
	function __destruct() { }
 
	function start()
	{
		$this->start = microtime(true);
	}
 
	function stop()
	{
		$this->stop = microtime(true);
		$interval = $this->stop - $this->start;
		if ($this->format == self::FORMAT_MS) { $interval *= 1000; }
		return $interval;
	}
}